package com.grgbanking.it.project.controller;



import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.grgbanking.it.project.component.WXProjectConstant;
import com.grgbanking.it.system.entity.GrgemEquipments;
import com.grgbanking.it.system.entity.User;
import com.grgbanking.it.system.service.IOaService;
import com.grgbanking.it.system.service.IUserService;

/**
 * 扫一扫及描述保修
 * WXOperationWorkScanController
 * 
 * @author 潘广伟
 * @Email p_3er@qq.com
 * @Date 2014-11-4 下午1:21:40
 * 
 * @version 1.0.0
 *
 */
@Controller
@RequestMapping("/wx/work")
public class WXOperationWorkScanController {
	private Integer agentId = WXProjectConstant.REPAIR_AGENT_ID;
	@Autowired
	private IOaService oaService;
	@Autowired
	private IUserService userService;

	/**
	 * 报修功能(扫一扫及描述保修)
	 * 
	 * repair
	 * 
	 * @param device
	 * @param request
	 * @param code
	 * @param state
	 * @return 
	 * @exception 
	 * @since  1.0.0
	 */
	@RequestMapping("repair/{device}")
	public ModelAndView repair(@PathVariable("device") String device,HttpServletRequest request, String code,Integer state){
		ModelAndView view = new ModelAndView();
		try {
			User user = userService.getUserByCode(code,agentId);
			request.setAttribute("user", user);
			if(user == null){
				view.setViewName("redirect:/wx/error.jsp");
			}else{
				//报修
				if(!device.equals("nodevice")){
					GrgemEquipments equipment = oaService.getEquipmentById(device);
					User equipmentKeeper = userService.getUserByUsername(equipment.getUseUser());
					request.setAttribute("equipment", equipment);
					request.setAttribute("keeper", equipmentKeeper);
				}
				
				view.setViewName("/wx/operation/repair.jsp");
			}
		}catch (Exception e) {
			e.printStackTrace();
		}
		
		return view;
	}
	
}
